<%@page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<head>
	<script type="text/javascript" src="plug-in/jquery/jquery-1.8.3.js"></script>
	<script type="text/javascript" src="plug-in/tools/curdtools_zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/Highcharts-4.2.4/highcharts.js" ></script>
	<script type="text/javascript" src="plug-in/easyui/jquery.easyui.min.1.3.2.js"></script>
	<script type="text/javascript" src="plug-in/lhgDialog/lhgdialog.min.js"></script>
	<link rel="stylesheet" href="plug-in/easyui/themes/default/easyui.css" type="text/css"></link>
	<link rel="stylesheet" href="plug-in/easyui/themes/icon.css" type="text/css"></link>
	<link rel="stylesheet" href="plug-in/tools/css/common.css" type="text/css"></link>
	<style type="text/css">
	.tabs-header{background: white;}
	</style>
<script type="text/javascript">
$(function(){
	$("#departId").on("change",function(){
		getCipCharData($(this).val());
	});
	getCipCharData();
});
var _year_condition;
function getCipCharData(departId){
	var posData = {};
	posData.departId = departId != undefined ? departId : '';
	posData.source = '<%=StaticValue.DIC_GENERATE_SOURCE_REAL_TIME%>';
	$.ajax({
		url : "cbsEsPlanIpController.do?getCipChartData",
		data : posData,
		cache : false,
		dataType : 'json',
		type : 'POST',
		success : function(data){
			if(data.success){
				var hgData = data.attributes.hgs;
				setHighchartData(hgData);
				_year_condition = data.obj;
			}else{
				tip(data.msg);
			}
		}
	});
}

function initallHighChartsOfPillar(serData){
	$("#highchartContainerOfPillar").highcharts({
		credits: {//去水印
         	text: '',
         	href: ''
     	},
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        plotOptions: {
            column: {
            	stacking: 'normal'
            }
        },
        tooltip: {
        	formatter: function () {
                return '<b>' + this.x + '</b><br/>' +
                    this.series.name + ': ' + this.y;
            }
        },
        xAxis: {
        	categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: ''
            },
            labels: {
                formatter: function () {
                    return this.value + ' 个';
                }
            }
        },
        legend: {
            enabled: false
        },
        series : serData
    });
}

function view(){
	var departId = $("#departId").val();
	addOneTab("实时生成巡检计划详情","cbsEsPlanIpController.do?goViewList&year="+_year_condition+"&departId="+departId+"&generateSource=<%=StaticValue.DIC_GENERATE_SOURCE_REAL_TIME%>");
}

function exportCips(){
	lockmask(true);
	myDownload("cbsEsPlanIpController.do?exportCips",{generateSource:'<%=StaticValue.DIC_GENERATE_SOURCE_REAL_TIME%>',ipYear:_year_condition});
	lockmask(false);
}

/**
 * 生成巡检计划(需要检查是否可以操作)
 */
function generateIp(){
	var posData = {
		generateSource:'<%=StaticValue.DIC_GENERATE_SOURCE_REAL_TIME%>',
		ipYear : _year_condition
	};
	$.dialog.confirm('是否确认生成巡检计划？',function(r) {
		if (r) {
			lockmask(true);
			$.ajax({
				url: "cbsEsPlanIpController.do?judgeCanGenerateEsIp",
				cache: false,
				dataType: 'json',
				type: 'POST',
				data: posData,
				success: function (data) {
					if (data.success) {
						$.post("cbsEsPlanIpController.do?genarateIp", posData, function (rsData) {
							lockmask(false);
							tip(rsData.msg);
						}, "json");
					} else {
						lockmask(false);
						tip(data.msg);
					}
				}
			});
		}
	});

}
var _hgsData;
function setHgsData(highChartData){
	_hgsData = highChartData;
}
function getHgsData(){
	return _hgsData;
}

function setHighchartData(highChartData){
	setHgsData(highChartData);//保存上数据
	var hgs = new Array();
	for(var index in getHgsData()){
		var hg = {};
		hg.name = highChartData[index].name;
		hg.data = highChartData[index].data;
		hg.stack = highChartData[index].stack;
		hgs.push(hg);
	}
	initallHighChartsOfPillar(hgs);//目前只能这样设置值
}

</script>
</head>
<body style="padding: 10px;margin: 0px auto;">
	<div class="pad_l_10">
		<table width="100%">
			<tr>
				<td width="60%">
					<label class="report_label">巡检服务商</label>
					<select id="departId" style="min-width: 250px;">
						<option value="">---请选择---</option>
						<c:forEach items="${tsDeparts}" var="item">
							<option value="${item.id }">${item.departname }</option>
						</c:forEach>
					</select>
				</td>
				<td width="30%">
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="generateIp()" >生成巡检计划</a>
				</td>
			</tr>
			<tr>
				<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="view()">查看</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-putout'" onclick="exportCips()">导出</a>
				</td>
				<td></td>
			</tr>
			<tr>
				<td colspan="2"><span id="message"></span></td>
			</tr>
		</table>
		<br />
		<div id="highchartContainerOfPillar" style="width: 99%;height:500px;margin:20px 20px;"></div>
	</div>
</body>
